<!DOCTYPE html>
<html>
<head>
    <script>
        let targetNumber = Math.floor(Math.random() * 50) + 1;
        let attempts = 0;
        const maxAttempts = 10;

        function guessNumber() {
            let userNumber = parseInt(prompt("请输入一个1到50之间的数字："));
            attempts++;

            if (attempts > maxAttempts) {
                alert("您的猜测次数已用完，正确数字是 " + targetNumber);
            } else if (userNumber > targetNumber) {
                alert("数字大了，继续猜，还剩余 " + (maxAttempts - attempts) + " 次机会");
            } else if (userNumber < targetNumber) {
                alert("数字小了，继续猜，还剩余 " + (maxAttempts - attempts) + " 次机会");
            } else {
                alert("猜对了！正确数字是 " + targetNumber);
            }
        }
    </script>
</head>
<body>
    <button onclick="guessNumber()">开始猜数字</button>
</body>
</html>
